<template>
    <el-select v-model="val" :multiple="multiple" :disabled="disabled" @change="onChange" filterable :placeholder="placeholder" :clearable="clearable" :collapse-tags="collapseTags">
        <el-option  v-bind="$attrs" v-for="item in options" :label="item[props.label]" :value="item[props.value]&&item[props.value].toString()" :key="item[props.value]" :disabled="item.disabled"></el-option>
    </el-select>
</template>

<script>
    export default {
        name: "EdSelect",
        props:{
            value:{
                type: [String,Number,Array],
                default:function () {
                    return '';
                }
            },
        },
        data() {
            return {
                options: this.$attrs.selectParams.options || [],
                val:"",
                props:this.$attrs.selectParams.props || {label:"label", value:"value"},
                multiple:this.$attrs.selectParams.multiple || false, // 多选
                disabled: this.$attrs.selectParams.disabled || false, // 禁用
                placeholder: this.$attrs.selectParams.placeholder || "请选择",
                clearable: this.$attrs.selectParams.clearable || false, // 清空
                collapseTags: this.$attrs.selectParams.collapseTags || false,
            }
        },
        watch:{
            '$attrs.selectParams.options'(val){
                this.options = val
            },
            value(val){              
                this.val = val
            }
        },
        created() {
            this.val = this.value || ""
        },
        methods:{
            onChange(event){
                this.$emit('input',event)
                this.$emit("emit-select-value",event)
            }
        }
    }
</script>

<style scoped>

</style>